<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 1. flex 布局，（内部div要有宽度）
    .box {
        width: 300px;
        height: 300px;
        background-color: aqua;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .a {
        width: 100px;
        height: 100px;
        background-color: bisque;
    } */
    /* 2. position 元素已知高度 宽度情况 */
    /* .box {
        width: 300px;
        height: 300px;
        background-color: aqua;
        position: relative;
    }
    .a {
        width: 100px;
        height: 100px;
        background-color: bisque;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -50px 0 0 -50px;
    }  */
    /* 3. position 内部元素需要设置宽高 */
    /* 若没设置宽高，则这种方法会将内部div铺满整个父级div */
    .box {
        width: 300px;
        height: 300px;
        background-color: aqua;
        position: relative;
    }
    .a {
        width: 100px;
        height: 100px;
        background-color: bisque;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
    } 
    /* 4. position 内部div 宽 高未知 */
    /* .box {
        width: 300px;
        height: 300px;
        background-color: aqua;
        position: relative;
    }
    .a {
        width: 100px;
        height: 100px;
        background-color: bisque;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
    }  */
</style>
<body>
    <div class="box">
        <div class="a">element</div>
    </div>
</body>
</html>